﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SlgLogic : MonoBehaviourSingleton<SlgLogic>
{
    public float searchRange = 5;
    public float baoweiRange = 5;
    public int baoweiJiaoDu = 140;


    EntitySTroop troop_1;
    EntitySTroop troop_2;
    EntitySTroop troop_3;

    EntitySTroop troop_4;
    EntitySTroop troop_5;
    EntitySTroop troop_6;
    List<EntitySTroop> leftTroops;
    List<EntitySTroop> rightTroops;

    public List<EntitySTroop> GetTroops(bool bLeft)
    {
        return bLeft ? leftTroops : rightTroops;
    }

    // Use this for initialization
    void Start () {
        leftTroops = new List<EntitySTroop>();
        rightTroops = new List<EntitySTroop>();
        List<SoldierVo> soldiers = new List<SoldierVo>()
        {
            new SoldierVo()
        };

        troop_1 = BattleEntityFactory.Instance.CreateBtEntity<EntitySTroop>() as EntitySTroop;
        troop_1.OnCreate(soldiers, new Vector3(-40, 0, -10), true,1);
        troop_2 = BattleEntityFactory.Instance.CreateBtEntity<EntitySTroop>() as EntitySTroop;
        troop_2.OnCreate(soldiers, new Vector3(-40, 0, 0), true,2);
        troop_3 = BattleEntityFactory.Instance.CreateBtEntity<EntitySTroop>() as EntitySTroop;
        troop_3.OnCreate(soldiers, new Vector3(-40, 0, 10), true,3);
        leftTroops.Add(troop_1);
        leftTroops.Add(troop_2);
        leftTroops.Add(troop_3);

        troop_4 = BattleEntityFactory.Instance.CreateBtEntity<EntitySTroop>() as EntitySTroop;
        troop_4.OnCreate(soldiers, new Vector3(-20, 0, -10), false,4);
        troop_5 = BattleEntityFactory.Instance.CreateBtEntity<EntitySTroop>() as EntitySTroop;
        troop_5.OnCreate(soldiers, new Vector3(-20, 0, 0), false,5);
        troop_6 = BattleEntityFactory.Instance.CreateBtEntity<EntitySTroop>() as EntitySTroop;
        troop_6.OnCreate(soldiers, new Vector3(-20, 0, 10), false,6);
        rightTroops.Add(troop_4);
        rightTroops.Add(troop_5);
        rightTroops.Add(troop_6);
        //troop_1.GetRoundPoint(new List<Vector3>(), Vector3.zero, Vector3.right, 1, 180, 1, 1);
    }

    // Update is called once per frame
    void Update () {
        BattleEntityFactory.Instance.OnUpdate(Time.deltaTime);

        KeyEvent();
	}
    public bool search = false;
    void KeyEvent()
    {
        //if (Input.GetKeyDown(KeyCode.Q))
        //{
        //    troop_1.LineSearch(new Vector3(BattleDef.GetWallAttackPoint(troop_1.bLeft).x, 0, troop_1.GetTroopCenter().z),
        //        Vector3.forward);

        //    troop_2.LineSearch(new Vector3(BattleDef.GetWallAttackPoint(troop_2.bLeft).x, 0, troop_2.GetTroopCenter().z),
        //        Vector3.forward);

        //    troop_3.LineSearch(new Vector3(BattleDef.GetWallAttackPoint(troop_3.bLeft).x, 0, troop_3.GetTroopCenter().z),
        //        Vector3.forward);
        //}

        //if (Input.GetKeyDown(KeyCode.W))
        //{
        //    //troop_1.RoundSearch(troop_2.GetTroopCenter(), Vector3.left, 2, 160,null,false);
        //    search = true;
        //}
        //if (search)
        //{
        //    troop_1.RoundSearch(troop_2.GetTroopCenter(), Vector3.left, 2, 160, null, false);
        //    troop_2.RoundSearch(troop_1.GetTroopCenter(), Vector3.right, 2, 160, null, false);
        //}

        //if (Input.GetKeyDown(KeyCode.W))
        //{
        //    troop_1.RestFormation();
        //}

        if (Input.GetKeyDown(KeyCode.Q))
        {
            for (int i = 0; i < leftTroops.Count; i++)
            {
                leftTroops[i].ChangeState(STroopStateDef.ForwardSearch);
            }
        }
    }
}
